<table cellpadding="0" cellspacing="0">
	<tbody>
        <tr>
            <td class="leftside">
           		<?php require_once("menu.php");?>
            </td>
            <td class="rightside">
                <div class="box" style="margin-left:10px; margin-right: 10px; float:left;">
                	<div id='title_menu' class="ui-corner-top">Advertisments Management</div>  
                    <div class="content" style="min-height: 150px;">
					<?php
                    	$sql = 'SELECT
								  `advertise`.*, `positions`.`position_name`, `category`.`cat_name`
								FROM
								  `advertise` INNER JOIN
								  `products` ON `advertise`.`pid` = `products`.`pid` INNER JOIN
								  `positions` ON `positions`.`id` = `advertise`.`position_id` INNER JOIN
								  `category` ON `category`.`cat_id` = `advertise`.`cat_id`';
						$q = $db->select_query($sql);
						$count = $db->rows($q);
					?>
                    <form action="#" method="post" id="ads-form">
                      <table class="list">
                        <thead>
                          <tr align="center">
                            <td>ลำดับ</td>
                            <td>รหัสประกาศ</td>
                            <td>สถานะ</td>
                            <td>หมวดหมู่</td>
                            <td>ตำแหน่ง</td>
                            <td>ระยะเวลาลงประกาศ</td>
                            <td>สิ้นสุดประกาศ</td>
                            <td>ลบประกาศ</td>
                          </tr>
                        </thead>
                        <tbody>
                        <?php
						$i = 1;
						while($rs = $db->fetch($q)){
						?>      
                          <tr>
                          	<td><?php echo $i;?></td>
                            <td><?php echo $rs['id'];?></td>
                            <td>
								<select name="status" id="status" adsid="<?php echo $rs['id'];?>" order_ads="<?php echo $rs['id'].'#'.$rs['pid'];?>">
                                    <option value="0" <?php ($rs['ads_status']==0)? print 'selected="selected"':'';?>>Pending</option>
                                    <option value="1" <?php ($rs['ads_status']==1)? print 'selected="selected"':'';?>>Approve</option>
                                    <option value="2" <?php ($rs['ads_status']==2)? print 'selected="selected"':'';?>>Expire</option>
                                </select>
                         	</td>
                            <td><?php ($rs['cat_name']=="")? print 'ทุกหมวด': print $rs['cat_name'];?></td>
                            <td><?php echo $rs['position_name'];?></td>
                            <td>
                            	<select name="period" id="period" adsid="<?php echo $rs['id'];?>">
                                	<option value="1" <?php ($rs['ads_period']==1)? print 'selected="selected"':'';?>>1 month</option>
                                    <option value="2" <?php ($rs['ads_period']==2)? print 'selected="selected"':'';?>>2 months</option>
                                    <option value="3" <?php ($rs['ads_period']==3)? print 'selected="selected"':'';?>>3 months</option>
                                    <option value="4" <?php ($rs['ads_period']==4)? print 'selected="selected"':'';?>>4 months</option>
                                    <option value="5" <?php ($rs['ads_period']==5)? print 'selected="selected"':'';?>>5 months</option>
                                    <option value="6" <?php ($rs['ads_period']==6)? print 'selected="selected"':'';?>>6 months</option>
                                    <option value="7" <?php ($rs['ads_period']==7)? print 'selected="selected"':'';?>>7 months</option>
                                    <option value="8" <?php ($rs['ads_period']==8)? print 'selected="selected"':'';?>>8 months</option>
                                    <option value="9" <?php ($rs['ads_period']==9)? print 'selected="selected"':'';?>>9 months</option>
                                    <option value="10" <?php ($rs['ads_period']==10)? print 'selected="selected"':'';?>>10 months</option>
                                    <option value="11" <?php ($rs['ads_period']==11)? print 'selected="selected"':'';?>>11 months</option>
                                    <option value="12" <?php ($rs['ads_period']==12)? print 'selected="selected"':'';?>>12 months</option>
                                </select>
                           	</td>
                            <td><?php echo ThaiTimeConvert($rs['ads_expire'],0,0);?></td>
                            <td align="center">
                            	<a href="#" adsid="<?php echo $rs['id'];?>" id="del_ads">
                                	<img src="images/delete.png" title="Delete this advertisment" />
                                </a>
                          	</td>
                          </tr>
                        <?php $i++; } ?>  
                        <?php if(empty($count)){?>
                          <tr>
                          	<td colspan="8">
                            	<div style="color: #0369C0; font-size: 18px; font-weight: bold; padding: 10px; text-align: center;">ยังไม่มีรายการประกาศแบบปักหมุด</div>
                            </td>
                          </tr>
                        <?php }?>
                        </tbody>
                      </table>
					</form>
                  </div>
                </div>            
            </td>
        </tr>
   	</tbody>
</table>